package demo3;

//牛客网:空调遥控
import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int p = in.nextInt();
        final int m = 1000000;
        int[] a = new int[n];
        int[] minn = new int[n];
        int[] maxn = new int[n];
        for(int i = 0; i<n; i++) {
            a[i] = in.nextInt();
            minn[i] = a[i] - p;
            maxn[i] = a[i] + p+1;
        }

        int[] st = new int[2000002];
        for(int i = 0; i<n; i++) {
            st[minn[i]+m]++;
            st[maxn[i]+m]--;
        }

        int count = 0, ret = 0;
        for(int i = 0; i<2000002; i++) {
            count += st[i];
            ret = Math.max(ret, count);
        }

        System.out.println(ret);
    }
}